
from sklearn.ensemble import RandomForestClassifier
from ReadData import Readdata
from sklearn.metrics import precision_score

class RandomForest(Readdata):

    def __init__(self):
        super(RandomForest, self).__init__()

    def trainAndtest(self, X_train, y_train, X_test, y_test):
        clf = RandomForestClassifier(min_samples_split=10)
        clf.fit(X_train, y_train)
        y_pred = clf.predict(X_test)

        print("随机森林分类")
        print("训练集得分:", clf.score(X_train, y_train))
        print("测试集得分:", clf.score(X_test, y_test))
        print("查准率:", precision_score(y_test, y_pred))




